Class: VideoSeoCheckService

Inherits:
Object
  • Object
show all
Defined in:
app/services/video_seo_check_service.rb

Constant Summary collapse

SEO_TITLE_MIN_LENGTH =

SEO constants - fallback if not loaded from initializer

50
SEO_TITLE_MAX_LENGTH =
65
TITLE_MAX_LENGTH =
150
SEO_META_DESCRIPTION_MIN_LENGTH =
120
SEO_META_DESCRIPTION_MAX_LENGTH =
155
SEO_SUB_HEADER_MIN_LENGTH =
50
SEO_SUB_HEADER_MAX_LENGTH =
70

Instance Method Summary collapse

Constructor Details

#initialize(video) ⇒ VideoSeoCheckService

Returns a new instance of VideoSeoCheckService.



11
12
13
# File 'app/services/video_seo_check_service.rb', line 11

def initialize(video)
  @video = video
end

Instance Method Details

#analyze_seo_healthObject

Returns a hash of all SEO health check results



16
17
18
19
20
21
22
23
# File 'app/services/video_seo_check_service.rb', line 16

def analyze_seo_health
  {
    meta_title: meta_title_quality_status,
    meta_description: meta_description_quality_status,
    sub_header: sub_header_quality_status,
    expanded_description: expanded_description_quality_status
  }
end

#detailed_analysisObject

Returns detailed analysis with character counts and recommendations



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/services/video_seo_check_service.rb', line 58

def detailed_analysis
  {
    meta_title: {
      status: meta_title_quality_status,
      current_length: @video.meta_title&.length || 0,
      min_length: SEO_TITLE_MIN_LENGTH,
      max_length: SEO_TITLE_MAX_LENGTH,
      recommendation: meta_title_recommendation
    },
    meta_description: {
      status: meta_description_quality_status,
      current_length: @video.meta_description&.length || 0,
      min_length: SEO_META_DESCRIPTION_MIN_LENGTH,
      max_length: SEO_META_DESCRIPTION_MAX_LENGTH,
      recommendation: meta_description_recommendation
    },
    sub_header: {
      status: sub_header_quality_status,
      current_length: @video.sub_header&.length || 0,
      min_length: SEO_SUB_HEADER_MIN_LENGTH,
      max_length: SEO_SUB_HEADER_MAX_LENGTH,
      recommendation: sub_header_recommendation
    },
    expanded_description: {
      status: expanded_description_quality_status,
      current_length: @video.expanded_description&.length || 0,
      min_length: 200,
      max_length: 1000,
      recommendation: expanded_description_recommendation
    }
  }
end

#expanded_description_quality_statusObject

Returns individual status for expanded description



50
51
52
53
54
55
# File 'app/services/video_seo_check_service.rb', line 50

def expanded_description_quality_status
  return 'missing' unless @video.expanded_description.present?
  return 'poor' if @video.expanded_description.length < 200 || @video.expanded_description.length > 1000

  'good'
end

#meta_description_quality_statusObject

Returns individual status for meta description



34
35
36
37
38
39
# File 'app/services/video_seo_check_service.rb', line 34

def meta_description_quality_status
  return 'missing' unless @video.meta_description.present?
  return 'poor' if @video.meta_description.length < SEO_META_DESCRIPTION_MIN_LENGTH || @video.meta_description.length > SEO_META_DESCRIPTION_MAX_LENGTH

  'good'
end

#meta_title_quality_statusObject

Returns individual status for meta title



26
27
28
29
30
31
# File 'app/services/video_seo_check_service.rb', line 26

def meta_title_quality_status
  return 'missing' unless @video.meta_title.present?
  return 'poor' if @video.meta_title.length < SEO_TITLE_MIN_LENGTH || @video.meta_title.length > SEO_TITLE_MAX_LENGTH

  'good'
end

#sub_header_quality_statusObject

Returns individual status for sub header



42
43
44
45
46
47
# File 'app/services/video_seo_check_service.rb', line 42

def sub_header_quality_status
  return 'missing' unless @video.sub_header.present?
  return 'poor' if @video.sub_header.length < SEO_SUB_HEADER_MIN_LENGTH || @video.sub_header.length > SEO_SUB_HEADER_MAX_LENGTH

  'good'
end